package com.bytedance.retrofit2.mime;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public final class TypedFile implements TypedInput, TypedOutput {
    private final String mimeType;
    private final File file;

    public TypedFile(File file) {
        this.mimeType = "application/octet-stream";
        this.file = file;
    }

    public final String mimeType() {
        return this.mimeType;
    }

    public final void writeTo(OutputStream out) throws IOException {
        byte[] bytes = new byte[4096];
        FileInputStream fis = new FileInputStream(this.file);
        try {
            while (true) {
                int len = fis.read(bytes);
                if (len == -1) {
                    break;
                }
                out.write(bytes, 0, len);
            }
        } catch (Throwable v0_1) {
            fis.close();
            throw v0_1;
        }

        fis.close();
    }

    public final InputStream in() throws IOException {
        return new FileInputStream(this.file);
    }

    public final long length() {
        return this.file.length();
    }

    public final String fileName() {
        return this.file.getName();
    }

    public final boolean equals(Object obj) {
        boolean v0;
        if (this == obj) {
            v0 = true;
        } else if ((obj instanceof TypedFile)) {
            v0 = this.file.equals(((TypedFile) obj).file);
        } else {
            v0 = false;
        }

        return v0;
    }

    public final int hashCode() {
        return this.file.hashCode();
    }

    public final String toString() {
        return this.file.getAbsolutePath() + " (" + this.mimeType + ")";
    }
}

